﻿using System.Configuration;

namespace ErrorDumper.Configuration {
    public class DataSourceElement : ConfigurationElement {

        [ConfigurationProperty("path", IsRequired = false)]
        public string Path {
            get { return (string)this["path"]; }
            set { this["path"] = value; }
        }

        [ConfigurationProperty("connectionStringName", IsRequired = false)]
        public string ConnectionStringName {
            get { return (string)this["connectionStringName"]; }
            set { this["connectionStringName"] = value; }
        }

        internal string GetValidatedConnectionStringName() {
            string conn = this.ConnectionStringName;

            if (string.IsNullOrEmpty(conn))
                throw new ConfigurationErrorsException(
                    "'connectionStringName' attribute must be specified",
                    ElementInformation.Source, ElementInformation.LineNumber);

            return conn;
        }
    }
}